package core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object core01_wordCount {


  def main(args: Array[String]): Unit = {

    val conf: SparkConf = new SparkConf()
      .setMaster("local[*]")
      .setAppName("core01")

    val sc: SparkContext = new SparkContext(conf)


    val dataRdd: RDD[String] = sc.textFile("data/word.txt")


    val resRdd: RDD[(String, Int)] = dataRdd
      .flatMap(_.split(" "))
      .map((_, 1))
      .reduceByKey(_ + _)


    resRdd.foreach(println)
  }

}
